<?php
if (!defined("IN_SYS")) exit("Access Denied!");
/**
 * Exception Handler
 *
 * @param   number  $errno
 * @param   string  $errstr
 * @param   string  $errfile
 * @param   string  $errline
 *
 * @return  void
 */
function my_exception_func($errno, $errstr, $errfile, $errline)
{
	if ($errno == 2048)
	{
		return true;
	}
	if ($errno != E_NOTICE)
	{
		include_once INCLUDE_DIR . "exception.lib.php";
		$msg        = new myException($errstr, $errno);
		$errfile    = str_replace(SYS_ROOT, '', $errfile);

		if ($errno == E_USER_ERROR || $errno == E_ERROR || $errno == E_PARSE || $errno == E_WARNING)
		{
			$msg->putlog($errno, $errstr, $errfile, $errline); // 写入错误日志
			$msg->output();
			exit;
		}
		else
		{
			$msg->output();
		}
	}
	elseif ($errno == E_NOTICE)
	{
		echo "<div style='font: 14px verdana'><b>Notice:</b> $errstr<br/><b>Error File:</b> $errfile: [$errline]</div>";
	}
    return true;
}

function daddslashes($string, $force = 0, $strip = FALSE)
{
	if (!MAGIC_QUOTES_GPC || $force)
	{
		if (is_array($string))
		{
			foreach ($string as $key => $val)
			{
				$string[$key] = daddslashes($val, $force, $strip);
			}
		}
		else
		{
			$string = addslashes($strip ? stripslashes($string) : $string);
		}
	}
	return $string;
}

function random($length, $numeric = 0) {
	PHP_VERSION < '4.2.0' ? mt_srand((double)microtime() * 1000000) : mt_srand();
	$seed = base_convert(md5(print_r($_SERVER, 1).microtime()), 16, $numeric ? 10 : 35);
	$seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
	$hash = '';
	$max = strlen($seed) - 1;
	for($i = 0; $i < $length; $i++) {
		$hash .= $seed[mt_rand(0, $max)];
	}
	return $hash;
}

function random_equal(){
	$seed = random(5, 1);
	$max = strlen($seed);
	$math = array('+', '-', '*');
	$hash = '';
	for ($i = 0; $i < $max; $i++){
		$hash .= ($i%2) ? $math[$seed[$i]%3] : $seed[$i];
	}
	return $hash;
}

function getrobot() {
	if(!defined('IS_ROBOT')) {
		$kw_spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla';
		$kw_browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla';
		if (!isset($_SERVER['HTTP_USER_AGENT']))
		{
			define('IS_ROBOT', FALSE);
		}
		elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'http://') === false && preg_match("/($kw_browsers)/i", $_SERVER['HTTP_USER_AGENT'])) {
			define('IS_ROBOT', FALSE);
		} elseif(preg_match("/($kw_spiders)/i", $_SERVER['HTTP_USER_AGENT'])) {
			define('IS_ROBOT', TRUE);
		} else {
			define('IS_ROBOT', FALSE);
		}
	}
	return IS_ROBOT;
}

function dhtmlspecialchars($string) {
	if(is_array($string)) {
		foreach($string as $key => $val) {
			$string[$key] = dhtmlspecialchars($val);
		}
	} else {
		$string = preg_replace('/&amp;((#(\d{3,5}|x[a-fA-F0-9]{4}));)/', '&\\1',
		str_replace(array('&', '"', '<', '>'), array('&amp;', '&quot;', '&lt;', '&gt;'), $string));
	}
	return $string;
}

function dsetcookie($var, $value = '', $life = 0, $prefix = 1, $httponly = false) {
	global $cookiepre, $cookiedomain, $cookiepath, $timestamp, $_SERVER;
	$var = ($prefix ? $cookiepre : '').$var;
	if($value == '' || $life < 0) {
		$value = '';
		$life = -1;
	}
	$life = $life > 0 ? $timestamp + $life : ($life < 0 ? $timestamp - 31536000 : 0);
	$path = $httponly && PHP_VERSION < '5.2.0' ? "$cookiepath; HttpOnly" : $cookiepath;
	$secure = $_SERVER['SERVER_PORT'] == 443 ? 1 : 0;
	if(PHP_VERSION < '5.2.0') {
		setcookie($var, $value, $life, $path, $cookiedomain, $secure);
	} else {
		setcookie($var, $value, $life, $path, $cookiedomain, $secure, $httponly);
	}
}

function clearcookies()
{
	global $logger_uid, $logger_user, $logger_pw;
	dsetcookie('sess_id');
	dsetcookie('sess_auth');
	dsetcookie('islogin');
	$logger_uid = 0;
	$logger_user = $logger_pw = '';
}

function template($file, $tpldir = '')
{
	global $post_header;
	if (defined("IS_WML") && !$post_header)
	{
		$post_header = true;
		header("Content-type: text/vnd.wap.wml; charset=utf-8");
		echo '<?xml version="1.0" encoding="utf-8"?>';
	}
	$tpldir = empty($tpldir) ? '' : trim(trim($tpldir), '/') . DS;
	$tplfile = TEMPLATE_DIR . $tpldir . $file . '.html';
	$objfile = DATA_DIR . 'templates'.DS.APP_CHANEL.DS.'_'.str_replace('/', '_', $tpldir).$file.'.tpl.php';
	$ttime = file_exists($objfile) ? filemtime($objfile) : 0;
	@checktplrefresh($tplfile, $tplfile, $ttime, $tpldir);
	return $objfile;
}

function checktplrefresh($tplfile, $subfile, $timecompare, $tpldir)
{
	if (empty($timecompare) || @filemtime($subfile) > $timecompare)
	{
		require_once INCLUDE_DIR . 'template.func.php';
		parse_template($tplfile, $tpldir);
		return true;
	}
	return false;
}

function page_url($page_index = 'page', $mpurl)
{
	$tmp_get = $_GET;
	if (isset($tmp_get[$page_index]))
	{
		unset($tmp_get[$page_index]);
	}
	$_gets = array();
	foreach ($tmp_get as $key => $val)
	{
		$_gets[] = "{$key}=".urlencode($val);
	}
	$mpurl .= '?'.implode("&", $_gets);
	unset($key, $val, $_gets);
	return $mpurl;
}

// 分页显示
function ajax_multi_page($page, $total, $current, $mpurl, $maxpages = 6)
{
	$mpurl = page_url('pg', $mpurl);

	$multipage = '';
	$mpurl .= strpos($mpurl, '?') ? '&amp;' : '?';
	if ($page > 1) // 只显示多于一个页面的列表
	{
		$offset = 2;
		if ($maxpages > $page)
		{
			$from = 1;
			$to = $page;
		}
		else
		{
			$from = $current - $offset;
			$to = $from + $maxpages - 1;
			if ($from < 1)
			{
				$to = $current + 1 - $from;
				$from = 1;
				if ($to - $from < $maxpages)
				{
					$to = $maxpages;
				}
			}
			elseif ($to > $page)
			{
				$from = $page - $maxpages + 1;
				$to = $page;
			}
		}
		for ($i = $from; $i <= $to; $i++)
		{
			$ajax_url = $mpurl.'pg='.$i;
			if ($i == $current) $multipage .= '<a href="javascript:;" class="fy2">'.$i.'</a>';
			else $multipage .=  '<a class="fy" href="javascript:;" onclick="pgajaxfunc(\''.$ajax_url.'\')">'.$i.'</a>';
		}
		$multipage = $multipage ? '<div class="fy_p">'.$multipage.'</div>' : '';
	}
	return $multipage;
}

// 分页显示
function www_multi_page($page, $total, $current, $mpurl, $maxpages = 6)
{
	$mpurl = page_url('pg', $mpurl);

	$shownum  = FALSE; // 显示总条数
	$lang['prev'] = '&#171;&nbsp;&nbsp;上一页';
	$lang['next'] = '下一页&nbsp;&nbsp;&#187;';

	$multipage = '';
	$mpurl .= strpos($mpurl, '?') ? '&amp;' : '?';
	if ($page > 1) // 只显示多于一个页面的列表
	{
		$offset = 2;
		if ($maxpages > $page)
		{
			$from = 1;
			$to = $page;
		}
		else
		{
			$from = $current - $offset;
			$to = $from + $maxpages - 1;
			if ($from < 1)
			{
				$to = $current + 1 - $from;
				$from = 1;
				if ($to - $from < $maxpages)
				{
					$to = $maxpages;
				}
			}
			elseif ($to > $page)
			{
				$from = $page - $maxpages + 1;
				$to = $page;
			}
		}
		$multipage = $current - $offset > 1 && $page > $maxpages ? '<a href="'.$mpurl.'pg=1" class="fy pre">首页</a>' : '';
		$multipage .= $current > 1 ? '<a href="'.$mpurl.'pg='.($current - 1).'" class="fy pre">'.$lang['prev'].'</a>&nbsp;&nbsp;&nbsp;' : '';
		for ($i = $from; $i <= $to; $i++)
		{
			$multipage .= $i == $current ? '<a href="javascript:;" class="fy2">'.$i.'</a>' : '<a class="fy" href="'.$mpurl.'pg='.$i.'">'.$i.'</a>';
		}
		$multipage .= $current < $page ? '&nbsp;&nbsp;&nbsp;<a href="'.$mpurl.'pg='.($current+1).'" class="fy">'.$lang['next'].'</a>' : '';
		$multipage .= $to < $page ? '<a href="'.$mpurl.'pg='.$page.'" class="fy last">末页</a>' : '';
		$multipage = $multipage ? '<div class="fy_p">'.($shownum ? '<em>&nbsp;'.$total.'&nbsp;</em>' : '').$multipage.'</div>' : '';
	}
	return $multipage;
}

//时间格式化
function sgmdate($timestamp='', $format=1) {
	global $_DSESSION;
	$dateformat = $_DSESSION['dateformat'];
	if(empty($timestamp)) {
		$timestamp = $GLOBALS['timestamp'];
	}
	$result = '';
	if($format) {
		$time = $GLOBALS['timestamp'] - $timestamp;
		if($time > 24*3600) {
			$result = gmdate($dateformat, $timestamp + $_DSESSION['timeoffset'] * 3600);
		} elseif ($time > 3600) {
			$result = intval($time/3600).'小时之前';
		} elseif ($time > 60) {
			$result = intval($time/60).'分钟之前';
		} elseif ($time > 0) {
			$result = $time.'秒之前';
		} else {
			$result = '刚刚';
		}
	} else {
		$result = gmdate($dateformat, $timestamp + $_DSESSION['timeoffset'] * 3600);
	}
	return $result;
}

function formhash()
{
	global $formhash, $timestamp, $logger_uid;
	if (empty($formhash))
	{
		$formhash = substr(md5(substr($timestamp, 0, -7).'|'.$logger_uid.'|'.md5($GLOBALS['system_auth_key']).'|'), 8, 8);
	}
	return $formhash;
}

function imgurl($url, $type = 'small')
{
	global $boardurl, $sess_id;
	$slash = strrpos($url, '/');
	if ($slash !== false)
	{
		$left = substr($url, 0, $slash+1);
		$right = substr($url, $slash+1);
		$url = $left.($type == 'small' ? '120_' : ($type == 'middle' ? '300_' : '')).$right;
	}
	return $boardurl.'attachments/'.$url;
}

function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
{
	global $system_auth_key;
    $ckey_length = 4;

    $key = md5($key ? $key : $system_auth_key);
    $keya = md5(substr($key, 0, 16));
    $keyb = md5(substr($key, 16, 16));
    $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';

    $cryptkey = $keya.md5($keya.$keyc);
    $key_length = strlen($cryptkey);

    $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
    $string_length = strlen($string);

    $result = '';
    $box = range(0, 255);

    $rndkey = array();
    for($i = 0; $i <= 255; $i++) {
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);
    }

    for($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
    }

    for($a = $j = $i = 0; $i < $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
    }

    if($operation == 'DECODE') {
        if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
            return substr($result, 26);
        } else {
            return '';
        }
    } else {
        return $keyc.str_replace('=', '', base64_encode($result));
    }
}

/**
 *  fopen封装函数
 *
 *  @param string $url
 *  @param int    $limit
 *  @param string $post
 *  @param string $cookie
 *  @param boolen $bysocket
 *  @param string $ip
 *  @param int    $timeout
 *  @param boolen $block
 *  @return responseText
 */
function at_fopen($url, $limit = 500000, $post = '', $cookie = '', $bysocket = false, $ip = '', $timeout = 15, $block = true)
{
	$return = '';
	$matches = parse_url($url);
	$host = $matches['host'];
	$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
	$port = !empty($matches['port']) ? $matches['port'] : 80;

	if($post)
	{
		$out = "POST $path HTTP/1.0\r\n";
		$out .= "Accept: */*\r\n";
		//$out .= "Referer: $boardurl\r\n";
		$out .= "Accept-Language: zh-cn\r\n";
		$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
		$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
		$out .= "Host: $host\r\n";
		$out .= 'Content-Length: '.strlen($post)."\r\n";
		$out .= "Connection: Close\r\n";
		$out .= "Cache-Control: no-cache\r\n";
		$out .= "Cookie: $cookie\r\n\r\n";
		$out .= $post;
	}
	else
	{
		$out = "GET $path HTTP/1.0\r\n";
		$out .= "Accept: */*\r\n";
		//$out .= "Referer: $boardurl\r\n";
		$out .= "Accept-Language: zh-cn\r\n";
		$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
		$out .= "Host: $host\r\n";
		$out .= "Connection: Close\r\n";
		$out .= "Cookie: $cookie\r\n\r\n";
	}
	$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
	if(!$fp)
	{
		return '';
	}
	else
	{
		stream_set_blocking($fp, $block);
		stream_set_timeout($fp, $timeout);
		@fwrite($fp, $out);
		$status = stream_get_meta_data($fp);
		if(!$status['timed_out'])
		{
			while (!feof($fp))
			{
				if(($header = @fgets($fp)) && ($header == "\r\n" ||  $header == "\n"))
				{
					break;
				}
			}

			$stop = false;
			while(!feof($fp) && !$stop)
			{
				$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
				$return .= $data;
				if($limit)
				{
					$limit -= strlen($data);
					$stop = $limit <= 0;
				}
			}
		}
		@fclose($fp);
		return $return;
	}
}

/**
 * 创建目录（如果该目录的上级目录不存在，会先创建上级目录）
 * 依赖于 ROOT_PATH 常量，且只能创建 ROOT_PATH 目录下的目录
 * 目录分隔符必须是 / 不能是 \
 *
 * @param   string  $absolute_path  绝对路径
 * @param   int     $mode           目录权限
 * @return  bool
 */
function at_mkdir($absolute_path, $mode = 0777)
{
	if (is_dir($absolute_path))
	{
		return true;
	}

	$root_path      = SYS_ROOT;
	$relative_path  = str_replace($root_path, '', $absolute_path);
	$each_path      = explode('/', $relative_path);
	$cur_path       = $root_path; // 当前循环处理的路径
	foreach ($each_path as $path)
	{
		if ($path)
		{
			$cur_path = $cur_path . '/' . $path;
			if (!is_dir($cur_path))
			{
				if (@mkdir($cur_path, $mode))
				{
					fclose(fopen($cur_path . '/index.htm', 'w'));
				}
				else
				{
					return false;
				}
			}
		}
	}

	return true;
}

/**
 * 删除目录,不支持目录中带 ..
 *
 * @param string $dir
 *
 * @return boolen
 */
function at_rmdir($dir)
{
	$dir = str_replace(array('..', "\n", "\r"), array('', '', ''), $dir);
	$ret_val = false;
	if (is_dir($dir))
	{
		$d = @dir($dir);
		if($d)
		{
			while (false !== ($entry = $d->read()))
			{
			   if($entry!='.' && $entry!='..')
			   {
				   $entry = $dir.'/'.$entry;
				   if(is_dir($entry))
				   {
					   at_rmdir($entry);
				   }
				   else
				   {
					   @unlink($entry);
				   }
			   }
			}
			$d->close();
			$ret_val = rmdir($dir);
		 }
	}
	else
	{
		$ret_val = unlink($dir);
	}

	return $ret_val;
}

function debug ()
{
    if (func_num_args() === 0)
        return;
        // Get all passed variables
    $variables = func_get_args();
    $output = array();
    foreach ($variables as $var) {
        $output[] = fdump($var, 1024);
    }
    echo '<pre class="debug">' . implode("\n", $output) . '</pre>';
}

function fdump (& $var, $length = 128, $level = 0)
{
    if ($var === NULL) {
        return '<small>NULL</small>';
    } elseif (is_bool($var)) {
        return '<small>bool</small> ' . ($var ? 'TRUE' : 'FALSE');
    } elseif (is_float($var)) {
        return '<small>float</small> ' . $var;
    } elseif (is_resource($var)) {
        if (($type = get_resource_type($var)) === 'stream' and $meta = stream_get_meta_data($var)) {
            $meta = stream_get_meta_data($var);
            if (isset($meta['uri'])) {
                $file = $meta['uri'];
                if (function_exists('stream_is_local')) {
                    // Only exists on PHP >= 5.2.4
                    if (stream_is_local($file)) {
                        $file = self::debug_path($file);
                    }
                }
                return '<small>resource</small><span>(' . $type . ')</span> ' . htmlspecialchars($file, ENT_NOQUOTES, 'utf-8');
            }
        } else {
            return '<small>resource</small><span>(' . $type . ')</span>';
        }
    } elseif (is_string($var)) {
        if (strlen($var) > $length) {
            // Encode the truncated string
            $str = htmlspecialchars(substr($var, 0, $length), ENT_NOQUOTES, 'utf-8') . '&nbsp;&hellip;';
        } else {
            // Encode the string
            $str = htmlspecialchars($var, ENT_NOQUOTES, 'utf-8');
        }
        return '<small>string</small><span>(' . strlen($var) . ')</span> "' . $str . '"';
    } elseif (is_array($var)) {
        $output = array();
        $space = str_repeat($s = '    ', $level);
        static $marker;
        if ($marker === NULL) {
            $marker = uniqid("\x00");
        }
        if (empty($var)) {
            // Do nothing
        } elseif (isset($var[$marker])) {
            $output[] = "(\n$space$s*RECURSION*\n$space)";
        } elseif ($level < 5) {
            $output[] = "<span>(";
            $var[$marker] = TRUE;
            foreach ($var as $key => & $val) {
                if ($key === $marker)
                    continue;
                if (! is_int($key)) {
                    $key = '"' . $key . '"';
                }
                $output[] = "$space$s$key => " . fdump($val, $length, $level + 1);
            }
            unset($var[$marker]);
            $output[] = "$space)</span>";
        } else {
            $output[] = "(\n$space$s...\n$space)";
        }
        return '<small>array</small><span>(' . count($var) . ')</span> ' . implode("\n", $output);
    } elseif (is_object($var)) {
        // Copy the object as an array
        $array = (array) $var;
        $output = array();
        // Indentation for this variable
        $space = str_repeat($s = '    ', $level);
        $hash = spl_object_hash($var);
        // Objects that are being dumped
        static $objects = array();
        if (empty($var)) {
            // Do nothing
        } elseif (isset($objects[$hash])) {
            $output[] = "{\n$space$s*RECURSION*\n$space}";
        } elseif ($level < 5) {
            $output[] = "<code>{";
            $objects[$hash] = TRUE;
            foreach ($array as $key => & $val) {
                if ($key[0] === "\x00") {
                    // Determine if the access is private or protected
                    $access = '<small>' . ($key[1] === '*' ? 'protected' : 'private') . '</small>';
                    // Remove the access level from the variable name
                    $key = substr($key, strrpos($key, "\x00") + 1);
                } else {
                    $access = '<small>public</small>';
                }
                $output[] = "$space$s$access $key => " . fdump($val, $length, $level + 1);
            }
            unset($objects[$hash]);
            $output[] = "$space}</code>";
        } else {
            // Depth too great
            $output[] = "{\n$space$s...\n$space}";
        }
        return '<small>object</small> <span>' . get_class($var) . '(' . count($array) . ')</span> ' . implode("\n", $output);
    } else {
        return '<small>' . gettype($var) . '</small> ' . htmlspecialchars(print_r($var, TRUE), ENT_NOQUOTES, 'utf-8');
    }
}

function responseAjax($success = '0', $message = '', $ext_array = array())
{
	$data = array('success' => $success, 'message' => $message);
	if (is_array($ext_array))
	{
		$data = array_merge($data, $ext_array);
	}
	exit(json_encode($data));
}

/**
 * 检查当前是否已经登录
 * 已经登录返回true 没有登录返回false
 *
 * @return boolean
 */
function isLogin()
{
	global $_DCOOKIE;
	$name = 'member_login';

	// 先检查是否有保存在Cookie中的登录状态
	if (isset($_DCOOKIE[$name]) && isset($_DCOOKIE[$name.'_info']))
	{
		return true;
	}

	return false;
}


// 不需要指定完全的地址 只要指定app和act
function requestLogin($url = '')
{
	global $_DCOOKIE;

	if ($url == 'login_to_cart') $forward_url = '/cart';
	$forward = !empty($url) ? $forward_url : 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	//$forward = strpos($forward, '/') === false ? $forward : str_replace('/', '',$forward);
	$_SESSION['login_backward'] = $forward;
	dsetcookie('login_backward', $forward, 86400, 1, true);

	if (!isLogin())
	{
		if ($url == 'login_to_cart')//购买时点注册不需要回答问题
		{
			echo '<script>window.top.location.href="/login?from=cart";</script>';
		}
		else
		{
			echo '<script>window.top.location.href="/login";</script>';
		}
	}

	exit;
}

/**
 * 登录后返回到登录前的页面
 */
function loginBackward()
{
	global $_DCOOKIE;

	$sess_back = isset($_SESSION['login_backward']) ? $_SESSION['login_backward'] : '/';
	$back = isset($_DCOOKIE['login_backward']) ? $_DCOOKIE['login_backward'] : '/';
	unset($_SESSION['login_backward']);
	dsetcookie('login_backward');

	//退出时是否跳转到首页
	$sess_back = (isset($_SESSION['to_home']) && $_SESSION['to_home'] == 1) ? '/' : $sess_back;
	unset($_SESSION['to_home']);

	header('Location: '.$sess_back);
}


/**
 * 取得当前登录信息
 * 注意：返回的信息是当前用户登录时存放在SESSION中的信息
 * 		如果在登录后修改了这些信息，此方法中返回的内容不会
 * 		与之同步。
 */
function getLoginInfo()
{
	global $_DCOOKIE;

	$name = 'member_login';

	if (isLogin())
	{
		$login = @$_DCOOKIE[$name.'_info'];
		if (!is_null($login))
		{
			$login = str_replace('\"', '"', $login);
			$login = str_replace('\\\\', '\\', $login);
			return json_decode($login, 1);
		}
	}

	return null;
}


/**
 * 跳转
 */
function feedback($msg = '' ,$url = '')
{
	$message = !empty($msg) ? $msg : '操作成功！';
	$forward_url = $url ? $url : '/';
	include(template('message'));
	exit(0);
}

function  _log_result($word, $file = 'default') {
	if (!is_file(DATA_DIR . "logs/".$file.".txt")) @touch(DATA_DIR . "logs/".$file.".txt");
    $fp = fopen(DATA_DIR . "logs/".$file.".txt","a");
    flock($fp, LOCK_EX) ;
    if (is_array($word) || is_object($word)) {
    	fwrite($fp,"Date:".strftime("%Y%m%d%H%M%S",time())."\n".var_export($word, true)."\n");
    } else {
    	fwrite($fp,"Date:".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n");
    }
    flock($fp, LOCK_UN);
    fclose($fp);
}

function fw_autoload ($class_name) 
{
    include(INCLUDE_DIR . DS .'Classes'. $class_name . '.php');
}
?>